<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>预警</title>
  <link rel="stylesheet" href="../../css/reset.css">
  <link rel="stylesheet" href="../../css/common.css">
  <link rel="stylesheet" href="../../css/style.css">
  <style>
    body {
      /*background-color: #0c1021;*/
    }

    .yujing_title {
      margin-bottom: 15px;
      width: 252px;
      height: 66px;
      background: url("yujing.png") no-repeat 100% 100%;
      background-size: 252px 66px;
    }

    .yujing_list {
      padding-left: 10px !important;
    }

    .yujing_list .yujing_item {
      margin-bottom: 8px;
      width: 500px;
      min-height: 70px;
      height: 70px!important;
      padding: 10px;
      font-size: 16px;
      color: #ffffff;
      background: url("../../img/yujing_bg.png") no-repeat 100% 100%;
      background-size: 100% 100%;
    }

    .yujing_list .time {
      padding: 0 20px;
    }

    .yujing_list .time:before {
      content: "";
      display: block;
      position: relative;
      top: 13px;
      left: -12px;
      width: 5px;
      height: 5px;
      background-color: #13d0ec;
      border-radius: 50%;
    }

    .yujing_list .info {
      padding: 0 20px;
    }

    .yujing_list .tip {
      color: #f49c2c;
    }
  </style>

</head>
<body class="yujing_page hide">
<div class="yujing_title"></div>
<div class="yujing_list"></div>

</body>
<script type="text/javascript" charset="utf-8" src="../../js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/superslide.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/common.js"></script>
<script>
  $(function () {

    /*const data = {
      "code": 200, "msg": null, "timestamp": "2021-11-17 10:00:37", "data": {
        "id": "JbkdrXwQJcuNLUg3RVFc2",
        "code": "jc_realdata_glj",
        "name": "给料机",
        "dataTable": null,
        "enabled": true,
        "onlineTimeout": 60000,
        "remark": "",
        "lastModifyDate": 1637114080000,
        "versionId": 17,
        "online": true,
        "onlineTimestamp": 1637114437475000000,
        "fields": [{
          "code": "WIC0601",
          "name": "9#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "72.0",
          "valueTimestamp": 1637114437443000000
        }, {
          "code": "WIC0602",
          "name": "10#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "0.0",
          "valueTimestamp": 1637114437449000000
        }, {
          "code": "WIC0603",
          "name": "11#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "72.0",
          "valueTimestamp": 1637114437455000000
        }, {
          "code": "WIAS0703",
          "name": "12#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "溶剂备用",
          "value": "0.0",
          "valueTimestamp": 1637114437460000000
        }, {
          "code": "WIAS0704",
          "name": "13#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "溶剂",
          "value": "21.82",
          "valueTimestamp": 1637114437466000000
        }, {
          "code": "WIAS0705",
          "name": "14#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "石灰石",
          "value": "7.16",
          "valueTimestamp": 1637114437470000000
        }, {
          "code": "WIAS0801",
          "name": "17#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "块煤",
          "value": "8.26",
          "valueTimestamp": 1637114437475000000
        }, {
          "code": "WC0601_1",
          "name": "09#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "72.0",
          "valueTimestamp": 1637114428049000000
        }, {
          "code": "WC0602_1",
          "name": "10#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "0.0",
          "valueTimestamp": 1637114428066000000
        }, {
          "code": "WC0603_1",
          "name": "11#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "72.0",
          "valueTimestamp": 1637114428076000000
        }, {
          "code": "WC0703",
          "name": "12#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "0.0",
          "valueTimestamp": 1637114428097000000
        }, {
          "code": "WC0704",
          "name": "13#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "21.57",
          "valueTimestamp": 1637114428107000000
        }, {
          "code": "WC0705",
          "name": "14#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "6.49",
          "valueTimestamp": 1637114428112000000
        }, {
          "code": "WC0801",
          "name": "17#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "8.5",
          "valueTimestamp": 1637114428152000000
        }, {
          "code": "WIAS0604",
          "name": "32#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "44.82",
          "valueTimestamp": 1637114428155000000
        }, {
          "code": "WC0604_1",
          "name": "32#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "44.0",
          "valueTimestamp": 1637114428080000000
        }, {
          "code": "WIAS0706",
          "name": "配料1#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "0.0",
          "valueTimestamp": 1637114428175000000
        }, {
          "code": "WIAS0707",
          "name": "配料2#定量给料机",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "镍精矿",
          "value": "0.0",
          "valueTimestamp": 1637114428178000000
        }, {
          "code": "WC0706",
          "name": "配料1#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "0.0",
          "valueTimestamp": 1637114428130000000
        }, {
          "code": "WC0707",
          "name": "配料2#定量给料机-设定值",
          "valueType": "String",
          "valueUnit": "",
          "defaultValue": null,
          "expectedValue": "",
          "expectedValueMin": 0.0,
          "expectedValueMax": 0.0,
          "remark": "设定值",
          "value": "0.0",
          "valueTimestamp": 1637114428133000000
        }],
        "tags": []
      }
    };
    console.log(data);*/

    getData();
    setInterval(function () {
      getData()
    }, 60000)

    function getData() {
      $.ajax({
        type: 'GET',
        url: '../../json/jc_equip_data_real.json',
        data: {},
        dataType: 'json',
        success: function (data) {
          console.log(data);
          const yujingData = [];

          let setData = data.data.fields.filter((item) => {
            return item.remark === '设定值'
          });
          let valueData = data.data.fields.filter((item) => {
            return item.remark !== '设定值'
          });

          for (let i = 0; i < valueData.length; i++) {
            for (let j = 0; j < setData.length; j++) {
              if (setData[j].name.indexOf(valueData[i].name) > -1) {
                valueData[i].setValue = setData[j].value
              }
            }
          }
          for (let i = 0; i < valueData.length; i++) {
            let valuei = Number(valueData[i].value);
            let setV = Number(valueData[i].setValue);
            // setV * 1.3
            console.log(valuei,setV * 1.1);
            if (valuei > setV) {
              valueData[i].status = '超出';
              yujingData.push(valueData[i])
            } else if (valuei < setV) {
              valueData[i].status = '低于';
              yujingData.push(valueData[i])
            }
          }

          $('.yujing_page').html(`<div class="yujing_title"></div><div class="yujing_list"></div>`)
          console.log(yujingData);
          if (yujingData.length) {
            $('.yujing_page').removeClass('hide')
          }else{
            $('.yujing_page').addClass('hide')
          }

          let listHtml = ``;
          for (let i = 0; i < yujingData.length; i++) {
            const itemDate = dateFormat(yujingData[i].valueTimestamp / 1000000, 'Y-m-d H:i:s')
            listHtml += `<div class="yujing_item">
          <div class="time">${itemDate}</div>
          <div class="info">
            <span class="devide_name">${yujingData[i].name || ''}</span>
            <span class="name">${yujingData[i].remark || ''}</span>
            <span class="tip">${yujingData[i].value || ''} 已${yujingData[i].status || ''}设定值</span>
          </div>
        </div>`
          }

          $('.yujing_list').html(listHtml);

          $(".yujing_page").slide({
            mainCell: ".yujing_list ",
            effect: "topLoop",
            autoPlay: true,
            vis: 3,
            scroll: 1,
            delayTime: 500,
          });
        },
        error: function (msg) {

        }
      });
    }

    /*
  ** 时间戳转换成指定格式日期
  ** eg.
  ** dateFormat(11111111111111, 'Y年m月d日 H时i分')
  ** → "2322年02月06日 03时45分"
  */
    function dateFormat(timestamp, formats) {
      // formats格式包括
      // 1. Y-m-d
      // 2. Y-m-d H:i:s
      // 3. Y年m月d日
      // 4. Y年m月d日 H时i分
      formats = formats || 'Y-m-d';

      var zero = function (value) {
        if (value < 10) {
          return '0' + value;
        }
        return value;
      };

      var myDate = timestamp ? new Date(timestamp) : new Date();

      var year = myDate.getFullYear();
      var month = zero(myDate.getMonth() + 1);
      var day = zero(myDate.getDate());

      var hour = zero(myDate.getHours());
      var minite = zero(myDate.getMinutes());
      var second = zero(myDate.getSeconds());

      return formats.replace(/Y|m|d|H|i|s/ig, function (matches) {
        return ({
          Y: year,
          m: month,
          d: day,
          H: hour,
          i: minite,
          s: second
        })[matches];
      });
    }

  })
</script>
</html>
